// pages/withdraw/withdraw.js
let md5 = require("../../utils/md5.js")
let axios = require("../../utils/util.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    payNum: "",
    payquota: "",
    paymoney: "",
    patNumStart:"",
    patmoneyStart:""
  },
  // 提现
  withdrawbind() {
    if (this.data.payNum) {
      if (this.data.paymoney) {
        if (this.data.paymoney > this.data.payquota) {
          wx.showToast({
            title: '您的可提现金额不足1',
            icon: 'none'
          })
        } else {
          let timestamp = (Date.parse(new Date()) / 1000).toString();
          let _token =
            "userId=" +
            app.globalData.user_id +
            "&type=1&token=" +
            app.globalData.userToken +
            "&time=" +
            timestamp +
            "&num=" +
            this.data.paymoney +
            "&account=" +
            this.data.payNum +
            "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
          let params = {
            userId: app.globalData.user_id,
            type: 1,
            num: this.data.paymoney,
            account: this.data.payNum,
            token: app.globalData.userToken,
            time: timestamp,
            sign: md5.hexMD5(_token),
          };
          axios.axios({
            url: "/user/postWithdraw",
            data: params
          }).then((res) => {
            console.log(res.data.result);
            wx.showToast({
              title: res.data.text,
              icon: 'none'
            })
            this.setData({
              patNumStart: "",
              patmoneyStart:""
            })
            setTimeout(()=>{
              this.getyue();
            },1500)
          })
        }
      } else {
        wx.showToast({
          title: '提现金额不能为空',
          icon: 'none'
        })
      }
    } else {
      wx.showToast({
        title: '银行卡账号不能为空',
        icon: 'none'
      })
    }
  },
  payNumChange(data) {
    this.setData({
      payNum: data.detail.value
    })
  },
  paymoneyChange(data) {
    // console.log(data.detail.value)
    this.setData({
      paymoney: data.detail.value
    })
  },
  getyue() {
    let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _token =
      "userId=" +
      app.globalData.user_id +
      "&token=" +
      app.globalData.userToken +
      "&time=" +
      timestamp +
      "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
    let params = {
      userId: app.globalData.user_id,
      token: app.globalData.userToken,
      time: timestamp,
      sign: md5.hexMD5(_token),
    };
    axios.axios({
      url: "/user/withdrawText",
      data: params
    }).then((res) => {
      // console.log(res.data.result),
      this.setData({
        payquota: res.data.result.balance,
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getyue()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})